package com.ssm.comm.session;

import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 *  类似于Redis感觉
 */
@Component
public class ShareSessionService {


    @PostConstruct
    public void init(){ // 做一个 session
        Map<String,Object> session = new LinkedHashMap<>() ;
        session.put("aabbc","asdasdasdsad");

        putSession("1122334455667788",session);
    }

    public String getSessionKey(String sid){
        return "SESSION:".concat(sid) ;
    }

    public boolean existSession(String sessionId){
        return RedisSession.existsSession(getSessionKey(sessionId));
    }

    public Map<String,Object> getSession(String session){
        return RedisSession.getSession(session) ;
    }

    public void putSession(String id,Map<String,Object> attributes){
        RedisSession.putSession(getSessionKey(id),attributes);
        aaaa(id);
    }

    public void removeRedisSession(String id){RedisSession.removeSession(getSessionKey(id));}


    public void aaaa(String id){
        //TODo redis key 续命 一小时
     }
}
